package com.lanou3g.musicenjoy.adapter;

import android.content.Context;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lanou3g.musicenjoy.R;
import com.lanou3g.musicenjoy.activities.HelloDrawerActivity;
import com.lanou3g.musicenjoy.entity.Special;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dllo on 15/11/2.
 */
public class SpecialRecycleAdapter extends RecyclerView.Adapter<SpecialRecycleAdapter.ViewHolder>{
    private Context mContext;
    private List<Special.AlbumlistEntity> datas;
    private HelloDrawerActivity activity;

    public SpecialRecycleAdapter (Context c,List<Special.AlbumlistEntity> datas){
        mContext=c;
        this.datas=datas;
        activity= (HelloDrawerActivity) c;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout specialLinearLayout;
        private ImageView specialImageView;
        private TextView specialTextView;
        public ViewHolder(View itemView) {
            super(itemView);
            specialImageView= (ImageView) itemView.findViewById(R.id.specialImageView);
            specialTextView= (TextView) itemView.findViewById(R.id.specialTextView);
            specialLinearLayout= (LinearLayout) itemView.findViewById(R.id.specialLinearLayout);
        }
    }

    @Override
    public SpecialRecycleAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(
                R.layout.fragment_special_item,null);
        ViewHolder holder=new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SpecialRecycleAdapter.ViewHolder holder, final int position) {
        Picasso.with(mContext).load(datas.get(position).getPic_small()).into(holder.specialImageView);
        holder.specialTextView.setText(datas.get(position).getTitle());
        holder.specialTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.intentRecycleView(position,datas);
            }
        });

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
}
